package object;

public class ObjectDemo {
    public static void main(String[] args) {
        //1.toString()的演示
        /*输出引用类型变量时默认调用Object类的toString()方法*/
        Point point = new Point(100,200);
        System.out.println(point);
        System.out.println(point.toString());

        /*java中任何类型与字符串的拼接结果都是字符串
        实际上jvm也是调用该类的toString()方法*/
        String str = "这是一个点"+point;
        System.out.println(str);


        /*调用Object类的equals(),内部还是在使用==比较地址*/
        Point point1 = new Point(12, 23);
        Point point2 = new Point(12, 23);
        System.out.println(point1==point2);//false,==比较的是两个对象的地址
        System.out.println(point1.equals(point2));//true

        //2.equals()的演示
        String s1 = new String("Hello!");
        String s2 = new String("Hello!");
        System.out.println(s1.equals(s2));//true String类中重写了equals()方法

        StringBuilder stringBuilder1 = new StringBuilder("Hello!");
        StringBuilder stringBuilder2 = new StringBuilder("Hello!");
        System.out.println(stringBuilder1.equals(stringBuilder2));//false StringBuilder类中没有重写equals方法

        System.out.println(s1.equals(stringBuilder1));//false

        /*练习*/
        /*String c1 = new String("javaclass");
        String c2 = new String("javaclass");
        System.out.println(c1.equals(c2));

        StringBuilder st1 = new StringBuilder("javaclass");
        StringBuilder st2 = new StringBuilder("javaclass");
        System.out.println(st1.equals(st2));

        System.out.println(c1.equals(st1));*/
    }
}
